//
//  CardContainerView.swift
//  swiftUIdemo
//
//  Created by Z.cy on 2025/1/9.
//

import SwiftUI

struct CardContainerView: View {
    @EnvironmentObject var appState :AppTabBarState
    @ObservedObject var viewModel:HomeViewModel
    @Namespace var namespace
    var card:UserCard
    var body: some View {
        if appState.isTabBarHidden {
            CardDetailView(namespace: namespace, card: card)
                .background(.white)
                .environmentObject(appState)
        }else{
            ZStack(alignment: .bottom){
                UserCardView(userCard: card, swipeAction: viewModel.nextUserCard)
                    .matchedGeometryEffect(id: card.id, in: namespace)
                    .environmentObject(appState)
                if viewModel.hasMoreCard {
                    HStack{
                        ForEach(ButtonType.allCases){ type in
                            RoundButton(type: type, action: {
                                switch type {
                                case .back:
                                    debugPrint("Roll Back")
                                case .no:
                                    viewModel.nextUserCard()
                                case .heart:
                                    viewModel.nextUserCard()
                                case .star:
                                    debugPrint("Super Like")
                                }
                            })
                            .frame(height:45)
                        }
                    }
                    .padding(.bottom, 15)
                }
            }
            .padding(.horizontal,20)
            .padding(.vertical, 20)
            
            
            
            
        }
        
    }
}

struct CardContainerView_Previews: PreviewProvider {
    static var previews: some View {
        CardContainerView(viewModel: HomeViewModel(), card: UserCard(name: "Jame", age: 23, place: "NY", zodiac: "Cancer", photos: ["User1", "User2"]))
            .environmentObject(AppTabBarState())
    }
}


